<template>
  <!-- 常规登录 -->
  <div class="common-login">
    <p class="title">后台管理系统</p>
    <!-- 背景 -->
    <div class="circlre" style="--x: 0"></div>
    <div class="circlre" style="--x: 1"></div>
    <div class="circlre" style="--x: 2"></div>
    <div class="circlre" style="--x: 3"></div>
    <div class="circlre" style="--x: 4"></div>

    <el-form-item label="用户名" prop="username">
      <el-input
        class="ps"
        type="text"
        v-model="loginForm.username"
        autocomplete="off"
      ></el-input>
    </el-form-item>

    <el-form-item label="密码" prop="password">
      <el-input
        type="password"
        v-model="loginForm.password"
        autocomplete="off"
      ></el-input>
    </el-form-item>

    <el-form-item label="验证码" prop="captcha">
      <el-input
        v-model="loginForm.captcha"
        type="text"
        class="captcha"
        @keydown.native.enter="submitFrom('loginForm')"
      ></el-input>
      <span class="captcha-svg">
        <i v-html="captcha" @click="getCaptcha"></i>
      </span>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('loginForm')" class="mit">
        提交
      </el-button>
    </el-form-item>
    <!-- 手机登录图标按钮 -->
    <el-form-item>
      <div class="sms">
        <!-- <svg></svg> -->
        <a
          href="javascript:;"
          @click="isSmsLogin = true"
          style="color: #fff; font-size: 16px"
        >
          切换短信登录
        </a>
      </div>
    </el-form-item>
  </div>
</template>
<script>
import * as api from "@/api/users";
export default {
  props: ["loginForm"],
  created() {
    api.getCaptcha().then((res) => {
      console.log(res);
    });
    this.getCaptcha();
  },
  data() {
    return {
      isSmsLogin: true,
      captcha: "",
      // loginForm: {
      //   username: "",
      //   password: "",
      //   captcha: "",
      // },
    };
  },
  methods: {
    submitForm(forName) {
      console.log(forName);
      // console.log(this.$refs);
      this.$emit("submit");
    },
    //封装一个获取验证码的方法
    getCaptcha() {
      api.getCaptcha().then((res) => {
        this.captcha = res.data.img;
      });
    },
  },
  //通过watch监听LoginForm的变化
  watch: {
    loginForm: {
      handler(newVal) {
        // console.log(newVal);
        this.$emit("syncLoginForm", newVal);
      },
      deep: true,
    },
  },
};
</script>
<style lang="less" scoped>
.title {
  width: 100%;
  text-align: center;
  font-size: 26px;
  position: relative;
  color: white;
  margin-bottom: 30px;
  margin-top: 20px;
}
.title::before {
  content: "";
  position: absolute;
  bottom: -5px;
  width: 0px;
  height: 3px;
  background-color: white;
  transition: 0.5s;
}
.title:hover:before {
  width: 156px;
}
.el-input,
.el-button {
  width: 300px;
}
.common-login {
  box-shadow: 0 0 10px 1px white;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  border-radius: 10px;
  width: 460px;
  padding: 20px;
  height: 400px;
  overflow: hidden;
  background-color: rgba(17, 16, 16, 0.1);
}
/deep/ .captcha {
  width: 150px;
  border-radius: 0px;
}
.mit {
  background: linear-gradient(90deg, #1596fb, #002dff);
  border-radius: 6px;
}
.sms {
  padding-left: 100px;
}
.captcha-svg {
  position: fixed;
  background-color: white;
  width: 150px;
  height: 40px;
  margin-top: 0.5px;
  border: 1 solid #606266;
  border-radius: 0 4px 4px 0;
}
.captcha {
  /deep/ .el-input__inner {
    border-radius: 4px 0 0 4px;
    border-right: 0;
    border: 0;
  }
}
.circlre {
  position: absolute;
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(5px);
  box-shadow: 0 25px 45px rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.circlre:nth-child(1) {
  top: -50px;
  right: -60px;
  width: 100px;
  height: 100px;
}
.circlre:nth-child(2) {
  top: 150px;
  right: -100px;
  width: 120px;
  height: 120px;
  z-index: 2;
}
.circlre:nth-child(3) {
  bottom: 50px;
  right: -60px;
  width: 80px;
  height: 80px;
  z-index: 2;
}
.circlre:nth-child(4) {
  bottom: -80px;
  left: 100px;
  width: 60px;
  height: 60px;
  z-index: 2;
}
.circlre:nth-child(5) {
  top: -80px;
  left: 140px;
  width: 60px;
  height: 60px;
  z-index: 2;
}
</style>
